﻿namespace PreGUI.Widgets
{
    using PreGUI.Interfaces;
    using UnityEngine;
    using UnityEngine.UI;

    /// <summary>
    /// PreGui Label Control
    /// </summary>
    public class PGLabel : IPGControl
    {
        public string Text;

        public GameObject LayoutControls(PreGui gui, GameObject parent, string windowName)
        {
            var gameObject = new GameObject("PGLabel");
            gameObject.transform.SetParent(parent.transform, false);

            var textComponent = gameObject.AddComponent<Text>();
            textComponent.font = gui.LabelSettings.Font;
            textComponent.fontSize = gui.LabelSettings.FontSize;
            textComponent.fontStyle = gui.LabelSettings.FontStyle;
            textComponent.color = gui.LabelSettings.FontColor;
            textComponent.text = Text;

            //var sizeFitter = gameObject.AddComponent<ContentSizeFitter>();
            //sizeFitter.horizontalFit = ContentSizeFitter.FitMode.Unconstrained;
            //sizeFitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize;
            return gameObject;
        }


        public IPGControl GenerateFromXmlNode(System.Xml.XmlNode node)
        {
            Text = node.InnerText.Trim();

            return this;
        }
    }
}

